package com.ljw.spring.annotation.conf;

import com.ljw.spring.annotation.bean.Dog;
import com.ljw.spring.annotation.bean.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @FileName ConfigOfPropertyValue
 * @Description TODO
 * @Author ljw
 * @Date 2021/2/2 22:34
 * @Version 1.0
 */
@Configuration
//使用@PropertySource读取外部配置文件中的k/v,保存到运行的环境变量中。
// （1）使用@Value(value = "${dog.hight}")取值，用在属性之上
//  (2)使用environment.getProperty（key）取配置文件中的值
@PropertySource(value = {"classpath:/dog.properties"})
public class ConfigOfPropertyValue {

    @Bean(value = {"user"})
    public User getUser() {
        System.out.println("创建实例");
        return new User("ljw");
    }

    @Bean(value = {"dog"})
    public Dog getDog() {
        System.out.println("创建Dog实例");
        return new Dog("lucky",1,"0.7");
    }
}
